﻿using System.Configuration;
using System.IO;
using MbUnit.Framework;
using MockingBird.Simulator.Framework.Configuration;
using Moq;

namespace MockingBird.Simulator.FunctionalTests.EngineTests
{

    using MockingBird.Common.Infrastructure.Logging;
    using MockingBird.Simulator.FunctionalTests.Common;
    using Simulator.Framework.Exceptions;


    [TestFixture]
    public class HandlerConfigurationSchemaManagementFixture
    {

        private string testDataRoot = ConfigurationManager.AppSettings["TestData_Root"];
        private HandlerConfiguration configuration;

        /// <summary>
        /// Test that the manager reports an exception for an invalid schema
        /// </summary>
        [Test]
        public void ExpectExceptionForInvalidSchema()
        {
            var mockLogger = new Mock<ILogger>();
            var manager = new HandlerConfigurationManager(mockLogger.Object, TestHelper.GetAppConfigData());

            manager.InitializeConfigurationData(GetInvalidSchemaFile());
            //Check for an exception
            Assert.Throws<HandlerConfigurationException>(() => manager.Validate());
            //check for the count of errors
            Assert.AreEqual(1, manager.ValidationErrors.Count);
        }

        #region "private helper methods"
        private string GetInvalidSchemaFile()
        {
            string invalidSchemaFile = ConfigurationManager.AppSettings["TestData_InvalidSchemaFileName"];
            invalidSchemaFile = Path.Combine(testDataRoot, invalidSchemaFile);
            return invalidSchemaFile;
        }

        private string GetValidConfigFile()
        {
            string invalidSchemaFile = ConfigurationManager.AppSettings["TestData_ValidConfigFileName"];
            invalidSchemaFile = Path.Combine(testDataRoot, invalidSchemaFile);
            return invalidSchemaFile;
        }

        #endregion


    }
}
